//
//  ViewController.m
//  Hand shadow
//
//  Created by A-01 on 2020/7/20.
//  Copyright © 2020 A-01. All rights reserved.
//

#import "ViewController.h"
#import "IntroduceViewController.h"
#import "LearnViewController.h"
#import "WorksViewController.h"
#import "GuessViewController.h"
#import "AppreciationViewController.h"
#import "DescriptionViewController.h"

@interface ViewController ()

@property (nonatomic, weak)UIImageView * titleImageView;
@property (nonatomic, weak)UIImageView * catImageView;
@property (nonatomic, strong)UIButton * one_button;
@property (nonatomic, strong)UIButton * two_button;
@property (nonatomic, strong)UIButton * three_button;
@property (nonatomic, strong)UIButton * four_button;
@property (nonatomic, strong)UIButton * five_button;
@property (nonatomic, strong)UIButton * six_button;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.backButton.hidden = YES;
    self.backView.image = [UIImage imageNamed:@"home_backView"];
    
    [self setupUI];
}


- (void)setupUI{
    
    UIImageView * titleImageView = [[UIImageView alloc] init];
    
    titleImageView.image = [UIImage imageNamed:@"Shadow"];
    
    self.titleImageView = titleImageView;
    
    [self.view addSubview:self.titleImageView];
    
    
    UIImageView * catImageView = [[UIImageView alloc] init];
    
    catImageView.image = [UIImage imageNamed:@"cat"];
    
    self.catImageView = catImageView;
    
    [self.view addSubview:self.catImageView];
    
    self.one_button = [self setupButtonWithBackImage:@"hand_06" title:@"Introduction"];
    [self.view addSubview:self.one_button];
    self.two_button = [self setupButtonWithBackImage:@"hand_05" title:@"Learn"];
    [self.view addSubview:self.two_button];
    self.three_button = [self setupButtonWithBackImage:@"hand_01" title:@"Works"];
    [self.view addSubview:self.three_button];
    self.four_button = [self setupButtonWithBackImage:@"hand_02" title:@"Guess"];
    [self.view addSubview:self.four_button];
    self.five_button = [self setupButtonWithBackImage:@"hand_04" title:@"Appreciation"];
    [self.view addSubview:self.five_button];
    self.six_button = [self setupButtonWithBackImage:@"hand_03" title:@"Description"];
    [self.view addSubview:self.six_button];
}


- (void)clickHomeButton:(UIButton *)button{
    
    if (button == self.one_button) {
        
        IntroduceViewController * introVC = [IntroduceViewController new];
        
        [self.navigationController pushViewController:introVC animated:YES];
    }else if (button == self.two_button){
        
        LearnViewController * learnVC = [LearnViewController new];
        
        [self.navigationController pushViewController:learnVC animated:YES];
    }else if (button == self.three_button){
        
        WorksViewController * workVC = [WorksViewController new];
        
        [self.navigationController pushViewController:workVC animated:YES];
    }else if (button == self.four_button){
        
        GuessViewController * guessVC = [GuessViewController new];
        
        [self.navigationController pushViewController:guessVC animated:YES];
    }else if (button == self.five_button){
        
        AppreciationViewController * appreVC = [AppreciationViewController new];
        
        [self.navigationController pushViewController:appreVC animated:YES];
    }else{
        
        DescriptionViewController * desVC = [DescriptionViewController new];
        
        [self.navigationController pushViewController:desVC animated:YES];
    }
}


- (void)viewDidLayoutSubviews{
    
    [super viewDidLayoutSubviews];
    
    [self.titleImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view);
        make.top.mas_equalTo(self.backButton.mas_bottom);
        make.width.mas_equalTo(200);
        make.height.mas_equalTo(90);
    }];
    
    [self.catImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.titleImageView.mas_trailing);
        make.bottom.mas_equalTo(self.titleImageView.mas_bottom).offset(-10);
        make.width.mas_equalTo(32);
        make.height.mas_equalTo(34);
    }];
    
    [self.three_button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.titleImageView.mas_leading).offset(30);
        make.top.mas_equalTo(self.titleImageView.mas_bottom).offset(70);
    }];
    
    [self.two_button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.three_button.mas_leading).offset(-30);
        make.top.mas_equalTo(self.three_button.mas_bottom).offset(-15);
    }];
    
    [self.one_button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.two_button.mas_leading).offset(15);
        make.bottom.mas_equalTo(self.two_button.mas_top).offset(-20);
    }];
    
    [self.four_button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.three_button.mas_trailing).offset(40);
        make.top.mas_equalTo(self.three_button.mas_bottom).offset(-20);
    }];
    
    [self.five_button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.four_button.mas_trailing).offset(70);
        make.top.mas_equalTo(self.three_button.mas_top).offset(-15);
    }];
    
    [self.six_button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.catImageView.mas_trailing).offset(40);
        make.top.mas_equalTo(self.catImageView.mas_top).offset(-5);
    }];
}


- (UIButton *)setupButtonWithBackImage:(NSString *)img title:(NSString *)title{
    
    UIButton * button = [UIButton new];
    
    [button setTitle:title forState:UIControlStateNormal];
    [button setBackgroundImage:[UIImage imageNamed:img] forState:UIControlStateNormal];
    NSString * titleColor;
    if ([title isEqualToString:@"Introduction"]) {
        
        titleColor = @"3BAABB";
    }else if ([title isEqualToString:@"Learn"]){
        
        titleColor = @"C4614C";
    }else if ([title isEqualToString:@"Works"]){
        
        titleColor = @"BF4046";
    }else if ([title isEqualToString:@"Guess"]){
        
        titleColor = @"AC6B90";
    }else if ([title isEqualToString:@"Appreciation"]){
        
        titleColor = @"43BF9D";
    }else{
        
        titleColor = @"97AC3F";
    }

    [button setTitleColor:[UIColor colorWithHexString:titleColor] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(clickHomeButton:) forControlEvents:UIControlEventTouchUpInside];
    button.titleLabel.font = [UIFont boldSystemFontOfSize:15];
    button.titleEdgeInsets = UIEdgeInsetsMake(17, 0, 0, 0);
    
    return button;;
}


@end
